package com.kmust.dream.wanderingdream.product.utils;

import com.kmust.dream.wanderingdream.comm.dto.Result;
import com.kmust.dream.wanderingdream.comm.pojo.ResultBean;
import com.kmust.dream.wanderingdream.comm.pojo.ReturnMessage;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.List;

@Component
public class ReturnUtils {
    public static ResultBean getList(Collection collection) {
        if (collection == null || collection.size() == 0)
            return Result.resultBean(ReturnMessage.GET_NULL.getCode(), ReturnMessage.GET_NULL.getMessage(), null);
        return Result.resultBean(ReturnMessage.GET_SUCCESS.getCode(), ReturnMessage.GET_SUCCESS.getMessage(), collection);
    }

    public static ResultBean getOne(Object res) {
        if (res == null)
            return Result.resultBean(ReturnMessage.GET_NULL.getCode(), ReturnMessage.GET_NULL.getMessage(), null);
        return Result.resultBean(ReturnMessage.GET_SUCCESS.getCode(), ReturnMessage.GET_SUCCESS.getMessage(), res);
    }

    public static ResultBean add(boolean status) {
        if (status)
            return Result.resultBean(ReturnMessage.INSERT_SUCCESS.getCode(), ReturnMessage.INSERT_SUCCESS.getMessage(), true);
        return Result.resultBean(ReturnMessage.INSERT_FAIL.getCode(), ReturnMessage.INSERT_FAIL.getMessage(), false);
    }
    public static ResultBean update(boolean status) {
        if (status)
            return Result.resultBean(ReturnMessage.UPDATE_SUCCESS.getCode(), ReturnMessage.UPDATE_SUCCESS.getMessage(), true);
        return Result.resultBean(ReturnMessage.UPDATE_FAIL.getCode(), ReturnMessage.UPDATE_FAIL.getMessage(), false);
    }
    public static ResultBean delete(boolean status) {
        if (status)
            return Result.resultBean(ReturnMessage.DELETE_SUCCESS.getCode(), ReturnMessage.DELETE_SUCCESS.getMessage(), true);
        return Result.resultBean(ReturnMessage.DELETE_FAIL.getCode(), ReturnMessage.DELETE_FAIL.getMessage(), false);
    }

    public static ResultBean realDelete(Integer rows) {
        if (rows > 0)
            return Result.resultBean(ReturnMessage.DELETE_SUCCESS.getCode(), ReturnMessage.DELETE_SUCCESS.getMessage(), true);
        return Result.resultBean(ReturnMessage.DELETE_FAIL.getCode(), ReturnMessage.DELETE_FAIL.getMessage(), false);
    }
}
